//封装的excel导出方法------高康
import axios from 'axios';
export function exportExcelJS(url)
{
    axios({
        method: "get",
        url: url,
        responseType: "blob", // 表明返回服务器返回的数据类型
        headers:{
            'Authorization':localStorage.getItem("jwt")
        }
    })
        .then((res) => {
            // 处理返回的文件流
            let blob = new Blob([res.data], {type: res.data.type});
            //获取fileName,截取content-disposition的filename；按=分割，取最后一个
            const fileName = decodeURI(res.headers['content-disposition'].split("=")[1], "UTF-8");
            let downloadElement = document.createElement("a");
            let href = window.URL.createObjectURL(blob); //创建下载的链接
            downloadElement.href = href;
            downloadElement.download = fileName; //下载后文件名
            document.body.appendChild(downloadElement);
            downloadElement.click(); //点击下载
            document.body.removeChild(downloadElement); //下载完成移除元素
            window.URL.revokeObjectURL(href); //释放blob
            this.$message.success("[excel表格]已成功导出!");
        })
        .catch(function (error) {
            // 请求失败处理
            console.log(error);
        });
}

